﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace PreProcessingLanguage
{
    class Test
    {
        Dictionary<string, int> list1Word = new Dictionary<string, int>();
        Dictionary<string, int> list2Word = new Dictionary<string, int>();
        Dictionary<string, double> P_LK = new Dictionary<string, double>();
        public void readData(string path1W, string path2W)
        {
            StreamReader sr = new StreamReader(path1W);
            string s;
            while ((s = sr.ReadLine()) != null)
            {
                string[] kv = s.Split(':');
                list1Word[kv[0]] = Int32.Parse(kv[1]);
            }
            sr.Close();
            sr = new StreamReader(path2W);
            while ((s = sr.ReadLine()) != null)
            {
                string[] kv = s.Split(':');
                list2Word[kv[0]] = Int32.Parse(kv[1]);
            }
            sr.Close();
        }
        public void process()
        {
            foreach (KeyValuePair<string,int> item in list2Word)
            {
                string[] word = item.Key.Split(' ');
                P_LK.Add(item.Key,Math.Pow(item.Value*1.0,2)/(list1Word[word[0]]*list1Word[word[1]]));
            }
        }
        public void writeData(string path)
        {
            StreamWriter sw = new StreamWriter(path);
            string t="";
            double tt = 0.0;
            foreach (KeyValuePair<string, double> pair in P_LK)
            {
                tt = Math.Round( pair.Value*1.0 , 4);
                if (tt != 0 && tt>0.002)
                {
                    t = pair.Key + ":" + tt;
                    sw.Write(t + "\n");
                }
            }
            sw.Flush();
            sw.Close();
        }
    }
}
